package com.htgd.gardenexpo.service.impl;

import com.htgd.gardenexpo.entity.GeConGisresourceArea;
import com.htgd.gardenexpo.dao.GeConGisresourceAreaDao;
import com.htgd.gardenexpo.service.GeConGisresourceAreaService;
import com.htgd.gardenexpo.vo.GisTitleCoordinate;
import com.htgd.gardenexpo.vo.KeyValue;
import com.htgd.gardenexpo.vo.ValueLabel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (GeConGisresourceArea)表服务实现类
 *
 * @author makejava
 * @since 2021-07-20 14:18:01
 */
@Service("geConGisresourceAreaService")
public class GeConGisresourceAreaServiceImpl implements GeConGisresourceAreaService {
    @Resource
    private GeConGisresourceAreaDao geConGisresourceAreaDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public GeConGisresourceArea queryById(Integer id) {
        return this.geConGisresourceAreaDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<GeConGisresourceArea> queryAllByLimit(int offset, int limit) {
        return this.geConGisresourceAreaDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param geConGisresourceArea 实例对象
     * @return 实例对象
     */
    @Override
    public GeConGisresourceArea insert(GeConGisresourceArea geConGisresourceArea) {
        this.geConGisresourceAreaDao.insert(geConGisresourceArea);
        return geConGisresourceArea;
    }

    /**
     * 修改数据
     *
     * @param geConGisresourceArea 实例对象
     * @return 实例对象
     */
    @Override
    public GeConGisresourceArea update(GeConGisresourceArea geConGisresourceArea) {
        this.geConGisresourceAreaDao.update(geConGisresourceArea);
        return this.queryById(geConGisresourceArea.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.geConGisresourceAreaDao.deleteById(id) > 0;
    }

    @Override
    public List<ValueLabel> getGis(String value) {
        return geConGisresourceAreaDao.getGis(value);
    }

    @Override
    public List<GisTitleCoordinate> getGisById(String gisIds) {
        String[] split = gisIds.split(",");
        Integer[] integers = new Integer[split.length];

        for (int i = 0; i < split.length; i++) {
            integers[i] = Integer.parseInt(split[i].trim());
        }
        return geConGisresourceAreaDao.getGisById(integers);
    }
}
